package cn.com.fuhuitong.main.home.vm

import android.app.Application
import androidx.lifecycle.MutableLiveData
import cn.com.fuhuitong.app.BaseApplication
import cn.com.fuhuitong.base.BaseViewModel
import cn.com.fuhuitong.base.SafeMutableLiveData
import cn.com.fuhuitong.http.BaseResponse
import cn.com.fuhuitong.http.HttpResponse
import cn.com.fuhuitong.http.ViewModelSubscribeListener
import cn.com.fuhuitong.main.home.entity.*
import cn.com.fuhuitong.main.home.mode.HomeManager
import io.reactivex.disposables.Disposable

class SigInViewModel(application: Application) : BaseViewModel(application) {

    private val homeManager: HomeManager = HomeManager()

    val signInListDataLiveData = MutableLiveData<HttpResponse<SignInListResponse>>()

    val baseDataLiveData = MutableLiveData<HttpResponse<BaseResponse>>()

    /**
     * 获取签到列表
     */
    fun signInLog() {
        val listener =
            object : ViewModelSubscribeListener<SignInListResponse>(signInListDataLiveData) {}
        val signInLogDisposable: Disposable = homeManager.signInLog(
            BaseApplication.userToken(), listener
        )
        dispose.add(signInLogDisposable)
    }

    /**
     * 用户签到
     */
    fun signInUser() {
        val listener =
            object : ViewModelSubscribeListener<BaseResponse>(baseDataLiveData) {}
        val signInUserDisposable: Disposable = homeManager.signInUser(
            BaseApplication.userToken(), listener
        )
        dispose.add(signInUserDisposable)
    }
}